<?php
// Push two scripts onto the end of our header array as they need to be displayed on every page
// Google AJAX API
$headers->headScript()->appendFile("http://www.google.com/jsapi?key=" . $config['googleajaxkey']);
$domain = parse_url($config['siteURL'], PHP_URL_HOST);
$headers->headScript()->captureStart();
include "./modules/gcmsSearch/GoogleSearch.js";
$headers->headScript()->captureEnd();

function gcmsSearch_onLoad($db) {
	if ($GLOBALS['authNamespace']->admin && isset($_REQUEST['searchSubmit'])) {
		$db->update('config', array('googleajaxkey' => $_POST['ajaxkey']));
		header("Location: " . $_SERVER['PHP_SELF'] . '?mod=gcmsSearch&action=manage');
		exit;
	}
}

function gcmsSearch_main($db, &$view, $translate) {
	if (!$GLOBALS['authNamespace']->admin)
		return;
	$view->assign('config', $GLOBALS['config']);
	$view->display('file:../../../modules/gcmsSearch/manage.tpl');
}

// Add a menu item
function gcmsSearch_adminMenu($translate) {
	$stack = array();
	$stack[] = $translate->_("Google Search Config");
	$stack['action=config'] = $translate->_("Google ID");
	return $stack;
}

/**
 * Generates the site search form.
 *
 * @param array $args Arguments to pass to the module in the form of an assoc array.
 */
function insert_gcmsSearch($args) {
	global $translate;
	if ($args['title'] == 'true') { echo "<h2>" . $translate->_("Search") . "</h2>\n"; }
	echo '<div id="searchForm">Loading...</div>';
}
?>
